$(".starTap").click(function () {

  $(this).addClass('currActive').siblings('.starTap').removeClass('currActive')

  $(".parcelRep").eq($(this).index()).removeClass('hide').siblings('.parcelRep').addClass('hide')
})

// 首页证书背景
$(".chapterTap").find('p').click(function(){
  var arr = ['./img/dot1.png','./img/dot4.png'];
  $(this).addClass('certificate').siblings('p').removeClass('certificate')
  $(".certifiDesc").eq($(this).index()).removeClass('hide').siblings('.certifiDesc').addClass('hide')
  $(".dot").css({'background':'url('+ arr[$(this).index()] +') no-repeat','background-size': '100% 100%'})
})

// 首页 专家证书
$(".specialists").find('li').click(function(){
  $(".adjustment").removeClass('listment')

  $(this).addClass('activeList').siblings('li').removeClass('activeList')
  $(".speciaDesc").eq($(this).index()).removeClass('hide').siblings('.speciaDesc').addClass('hide')
  switch($(this).index()){
    case 0 : speciaAdd('tag'); break;
    case 1 : addspeci();break;
    case 2 : site('tag');break;
    case 3 : organization('tag');break;
  }
})

// 回到顶部
$(".returnTop").click(function () {

  $("html,body").animate({
    scrollTop: '0px',
  }, 300);

})

// 首页证书
function addspeci(){
  let str = `
    <div class="uskBox">
      <p class="uskill">
        <a href="certificate.html">
          <img src='./img/skill.png'>
        </a>
      </p>
    </div>
  `
  $(".adjustment").html(str);
}

let AjaxUrl = 'https://jzmy.jz1x.com/';
let page = 1,limit = 12;

if( $(".specialists").length ){
  speciaAdd('tag');
}
// 机构
function organization(road) {
  let pageMax = limit;
  if( road == 'tag' ){
    pageMax = 18
  }
  $.get(AjaxUrl + 'userService/jinZhiIndex/brand/selBrand', {
      number: pageMax,
      current: page,
      workAddress: '',
      brandType: '',
      sleBrandTime: '',
      status: 1,
      brandName: $.trim($(".searchName").val())
    },
    function (data) {
      let records = data.data.records
      let str = ``, srr = ``;
      const pages = [];

      $(".loadinglast").hide();
      
      records.forEach(function (v,k) {

        const pageMsg = Math.floor(k / 6);
        if (!pages[pageMsg]) {
          pages[pageMsg] = []
        }
        pages[pageMsg].push(v);

        if (v.brandType == 0) {
          if( road != 'tag' ){
            str += `
                <div class="kindergarten">

                  <div class="kindergartenImg">
                    <img src="${v.brandlogo}" alt="">
                  </div>

                  <div class="kindergartenBox">
                    <div class="kindergartenName">${v.brandName}</div>
                    <dl class="kindergartenDl">
                      <dd><span class="kindergartenBrand">品牌类型：</span><span class="kindergartenDesc">幼儿照护</span></dd>
                      <dd><span class="kindergartenBrand">成立时间：</span><span class="kindergartenDesc">${v.brandTime}</span></dd>
                      <dd><span class="kindergartenBrand">工作地址：</span><span class="kindergartenDesc">${v.detailsAddress}</span></dd>
                    </dl>
                  </div>

                </div>
            `
          }
        }
      })

      if( road == 'tag' ){
        str = ``;
        pages.forEach(function(v){
          str = ``;
          v.forEach(function(val){
            str += `
              <div class="ubox">
                <a href="organization.html">
                  <p class="uimg"><img src="${val.brandlogo}" alt=""></p>
                  <p class="uname" title="${val.brandName}">${val.brandName}</p>
                </a>
              </div>
            `;
          })
          srr += `
            <div class="swiper-slide">
              ${str}
            </div>
          `;
        })

        $(".adjustment").html(`
          <div class="swiper mySwiper" id="per">
            <div class="swiper-wrapper">
              ${srr}
            </div>
            <div class="swiper-pagination"></div>
          </div>
        `)
        forObject("#per");

      }

      if( road != 'tag' ){
        $(".organizationList").html(str)
        putInfo(data.data.total,organization);
      }

    });

}


// 站点
function site(road) {

  let pageMax = limit;
  if( road == 'tag' ){
    pageMax = 18
  }

  $.get(AjaxUrl + 'site/organizion/yyrSelExaminationPoint', {
      number: pageMax,
      current: page,
      name: $.trim($(".searchName").val())
    },
    function (data) {
      let records = data.data.records;
      let str = ``, srr = ``;
      const pages = [];
      $(".loadinglast").hide();

      records.forEach(function (v,k) {
        const pageMsg = Math.floor(k / 6);
        if (!pages[pageMsg]) {
          pages[pageMsg] = []
        }
        pages[pageMsg].push(v);

        if( road != 'tag' ){
          str += `
              <div class="kindergarten siteBox">

                <div class="kindergartenImg">
                  <img src="${v.orgPhoto ? v.orgPhoto : './img/nologo.png'}" alt="">
                </div>
        
                <div class="kindergartenBox">
                  <div class="kindergartenName" style="font-size:16px;font-weight:bold">${v.name ? v.name : '暂无'}</div>
                  <dl class="kindergartenDl">
                    <dd><span class="kindergartenBrand">负责证书：</span><span class="kindergartenDesc">${v.profileName ? v.profileName : '暂无'}</span></dd>
                    <dd><span class="kindergartenBrand">联 系 人：</span><span class="kindergartenDesc">${v.contacts ? v.contacts : '暂无'}</span></dd>
                    <dd><span class="kindergartenBrand">地 址：</span><span class="kindergartenDesc">${v.address ? v.address :'暂无'}</span></dd>
                  </dl>
                </div>
        
              </div>
          `
        }      
      })

      if( road == 'tag' ){
        str = ``;
        pages.forEach(function(v){
          str = ``;
          v.forEach(function(val){
            str += `
              <div class="ubox">
                <a href="site.html">
                  <p class="uimg"><img src="${val.orgPhoto ? val.orgPhoto : './img/nologo.png'}" alt=""></p>
                  <p class="uname" title="${val.name}">${val.name}</p>
                </a>
              </div>
            `;
          })
          srr += `
            <div class="swiper-slide">
              ${str}
            </div>
          `;
        })

        $(".adjustment").html(`
          <div class="swiper mySwiper" id="pagina">
            <div class="swiper-wrapper">
              ${srr}
            </div>
            <div class="swiper-pagination"></div>
          </div>
        `)
        forObject("#pagina");
      }

      if( road != 'tag' ){
        $(".siteList").html(str)
        putInfo(data.data.total,site);
      }

    });

}


// 专家
function speciaAdd(road) {

  let pageMax = limit;
  if( road == 'tag' ){
    pageMax = 24
  }

  $.post(AjaxUrl + 'userService/jinZhiIndex/experts/expertsList', {
      number: pageMax,
      current: page,
      type: '1',
      name: $.trim($(".searchName").val())
    },
    function (data) {
      let records = data.data.type.list;
      let str = ``, srr = ``; 
      const pages = [];
      $(".loadinglast").hide();

      records.forEach(function (v,k) {

        const pageMsg = Math.floor(k / 8);

        if (!pages[pageMsg]) {
          pages[pageMsg] = []
        }
        pages[pageMsg].push(v);

        if( road != 'tag' ){
          str += `
            <div class="figureBox figureHover">
              <div class="figureImg">
                <div class="figurePhoto">
                  <img src="${v.enclosure}" alt="">
                </div>
                <div class="figureName">
                  ${v.name}
                </div>
              </div>
              <div class="figureContent">
                  ${v.ellipsis}
              </div>
              <div class="figureContentAll">
                  ${v.honor}
              </div>
            </div>
          `
        }
      })

      if( road == 'tag' ){
        str = ``;
        pages.forEach(function(v){
          str = ``;
          v.forEach(function(val){
            str += `
                <div class="urdbox">
                  <a href="specialist.html">
                    <p class="urad"><img src="${val.enclosure}" alt=""></p>
                    <p class="uname" title="${val.name}">${val.name}</p>
                  </a>
                </div> 
            `;
          })
          srr += `
            <div class="swiper-slide">
              ${str}
            </div>
          `;
        })

        $(".adjustment").addClass('listment')
        $(".adjustment").html(`
          <div class="swiper mySwiper" id="swi">
            <div class="swiper-wrapper">
              ${srr}
            </div>
            <div class="swiper-pagination"></div>
          </div>
        `)
        forObject('#swi');
      }
      if( road != 'tag' ){
        $(".speciaAdd").html(str)
        putInfo(data.data.type.listSize,speciaAdd);
      }
    });
}

// 证书查询

$(".butForm").click(function () {

  let name = $(".form").find('.name').find('input').val().trim();
  let id = $(".form").find('.id').find('input').val().trim();
  if (name.length <= 0) {
    $(".name").find('.warning').show()
  }

  if (id.length <= 0) {
    $(".id").find('.warning').show()
  }

  setTimeout(function(){
    $(".infoTips").hide()
  },3000)

  $(".infoTips").hide();
  $.get(AjaxUrl + 'userService/jinZhiIndex/userServer/yyrselCertificate', {
      name: name,
      idCard: id
    },
    function (data) {

      if (data.code == 0) {
        
        if( data.data <= 0 ){
          $(".infoTips").show().html('未查询到相关证书');
        }

        data.data.forEach(function(v){
            window.localStorage.setItem('swiper', JSON.stringify(data.data))
            location.href = 'certificateResult.html';
        })
      }
      if (data.code == -1) {
        $(".infoTips").show().html(data.msg)
      }

    }
  )

})


var locages = [];
if( $(".clear").length ){

  let arr = ['通知公告','政策信息','企业动态'];
  let i = 0;
  let set = null;

  set = setInterval(function(){
    if( i < arr.length ){
      announcement(arr[i]);
      i++;
    }else{
      clearInterval(set);
      i = 0;
      window.localStorage.setItem('locages', JSON.stringify(locages) );
      cacheData()
    }
  },50)
}

// announcement('通知公告');
// 通知公告
function announcement(ev){
  let locage = [];
  $.get(AjaxUrl + 'jinZhiIndex/yyrindexArticle', {
      number: 2,
      current: 1,
      secondColumn: ev
    },
    function (data) {
      let str = ``;
      locages.push(JSON.stringify(data.data.indexList))
    }
  )
}

// cacheData()
function cacheData(){
  let locages = JSON.parse(window.localStorage.getItem('locages'));
  let str = '' ,  srr = '';
  locages.forEach(function(v,k){
    str = '';
    JSON.parse(v).forEach(function(val){
      str += `
            <div class='listDiv' >
              <a href="articleInfo.html?id=${val.id}">
                <div class="imgBox">
                  <img src="${val.thumbnail ? val.thumbnail : './img/little.png'}" alt="">
                </div>
                <div class="listBox">
                  <div class="listle" > ${val.title}</div>
                  <div class="listCont" >
                      ${getSimpleText(val.contents)}
                  </div>
                </div>
              </a>
            </div>
        `;
    })
    srr += `
        <div class="swiper-slide">
          ${str}
        </div>
          `
  })

  $(".clearTeam").find(".list").html(`
    <div class="swiper mySwiper" id='myswiper'>
      <div class="swiper-wrapper">
        ${srr}
      </div>
      <div class="swiper-pagination"></div>
    </div>
  `);
  forObject("#myswiper");
}


function putInfo(data,callBack){
  
  // 分页
  layui.use(['laypage'], function () {
    var laypage = layui.laypage;

    //自定义样式
    laypage.render({
      elem: 'content-page', //容器ID
      count: data, //共有多少条数据
      limit: limit, //每页显示的数据
      curr: page,
      theme: '#FF73AA',
      layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
      jump: function(obj,first){
        page = obj.curr
        limit = obj.limit
        if( !first ){
          page = obj.curr;
          callBack.call()
        }
      }, //回调函数，用于发生其他改变
      first: '首页',
      last: '尾页',
    })
  })

}

function getSimpleText(html) {
  const re1 = new RegExp("<.+?>", "g"); // 匹配html标签的正则表达式，"g"是搜索匹配多个符合的内容
  const arrEntities = { 'lt': '<', 'gt': '>', 'nbsp': ' ', 'amp': '&', 'quot': '"', 'ldquo': '“', 'mdash': '—', "rdquo": '”' };
  return html.replace(re1, '').replace(/&(lt|gt|nbsp|amp|quot|ldquo|mdash|rdquo);/ig, function (all, t) {
    return arrEntities[t];
  });
}


function forObject(obj){
  var swiper = new Swiper(obj, {
          cssMode: true,
          loop:true,
          autoplay:true,
          pagination: {
            el: ".swiper-pagination",
            clickable: true,
          },
      });
}

$(document).ready(function(){

  var swiper = new Swiper(".bg", {
    cssMode: true,
    loop:true,
    autoplay:true,
    pagination: {
      el: ".swiper-pagination",
      clickable: true,
    }
  });

  var swiper = new Swiper("#swiper", {
    cssMode: true,
    loop:true,
    autoplay:true,
    pagination: {
      el: ".swiper-pagination",
      clickable: true,
    }
  });

})